
#include "Mutex.h"

#ifdef _WIN32

Mutex::Mutex() :
_isLock(false)
{
	InitializeCriticalSection(&this->_criticalSection);
}

Mutex::~Mutex()
{
	DeleteCriticalSection(&this->_criticalSection);
}

void Mutex::Lock()
{
	_isLock = true;
	EnterCriticalSection(&this->_criticalSection);
}

void Mutex::Unlock()
{
	LeaveCriticalSection(&this->_criticalSection);
	_isLock = false;
}

#else

Mutex::Mutex() :
_isLock(false)
{
        pthread_mutex_init(&_mutex, NULL);
}

Mutex::~Mutex()	
{
	pthread_mutex_destroy(&_mutex);
}

void Mutex::Lock()
{
	_isLock = true;
	pthread_mutex_lock(&this->_mutex);
}

void Mutex::Unlock()
{
	pthread_mutex_unlock(&this->_mutex);
	_isLock = false;
}

#endif

bool Mutex::IsLock()
{
	return _isLock;
}